Query Statistics Collection PRO
The Health.queryStatisticsCollection() method retrieves time-based aggregated statistics for a given HealthQuantityType over a specified date range. It returns a HealthStatisticsCollection object, which contains multiple HealthStatistics entries aligned to defined time intervals (such as daily, weekly, or monthly).
This method is ideal for analyzing trends, building charts, and generating historical summaries of health data.
Method Signature
Parameters
Return Value
Returns a Promise that resolves to a HealthStatisticsCollection object. This collection includes statistics for each time interval between the start and end dates, aligned by the anchor date and grouped using the provided intervalComponents.
Example: Retrieve Daily Step Count Statistics for the Past 7 Days
Notes
- If no data exists for a specific interval, its corresponding
HealthStatisticsentry may returnnullvalues. - Intervals are aligned using the
anchorDate, and the grouping is defined byintervalComponents. - If you only need overall statistics for the full range without interval grouping, use
Health.queryStatistics()instead.
